<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>课程字典分类管理</title>
<meta name="decorator" content="default"/>
<script type="text/javascript">
	//url
	var listUrl = '${ctx}/sys/dictCategory/';
	var cardUrl = '${ctx}/sys/dictCategory/form';
	var sortUrl = listUrl+'updateSort';
	var statusUrl = listUrl+"ajaxUpdateStatus";
	var ajaxSortUrl = listUrl+'ajaxUpdateSort';
	var ajaxShowUrl = listUrl+'ajaxUpateShow';
	$(document).ready(function() {
	
		
	});
	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
		return false;
	}
	
	function add() { //新增记录
		var url = cardUrl + '?opt=add';
		parent.freshTabs(jQuery(window.parent.document).find('[link="iframeContent2"]'), url);
	}
	
	function edit(obj, isEdit) { //修改记录
		var curentTr = null;
		if (obj != null) {
			curentTr = jQuery(obj).parents('tr')[0];
		} else {
			var table = jQuery("#contentTable");
			var checkboxs = jQuery('input[attrname="sort"]:checked', table);
			if (checkboxs.length == 0) {
				alertx("请选择一行数据！");return;
			} else if (checkboxs.length > 1) {
				alertx("只能选择一行数据！");return;
			}
			curentTr = jQuery(checkboxs[0]).parents('tr')[0];
		}
		var id = jQuery('[attrname="id"]', curentTr).val();
		if (id != null || id != '') {
			var opt = (isEdit==true || isEdit == null) ? 'edit' : 'other';
			var url = cardUrl + '?opt=' + opt + '&id=' + id;
			parent.freshTabs(jQuery(window.parent.document).find('[link="iframeContent2"]'), url);
			//parent.selectCheckNode(id);
		}
	}
	
	function detail(obj) { //查看记录详情
		edit(obj, false);
	}
	
	function del(obj) { //删除记录
		if (obj != null) { //单个删除
			var curentTr = jQuery(obj).parents('tr')[0];
			var id = jQuery('[attrname="id"]', curentTr).val();
			var url = listUrl + 'delete?id=' + id;
			confirmx('确认要删除该课程字典分类记录吗？', function() {
				ajaxDelete(id);
			});
		} else { //批量删除
			var table = jQuery("#contentTable");
			var checkboxs = jQuery('input[attrname="sort"]:checked', table);
			if (checkboxs.length == 0) {
				alertx("请选择至少一行数据！");
				return;
			}
			var ids = [];
			for (var i = 0; i < checkboxs.length; i++) {
				var curentTr = jQuery(checkboxs[i]).parents('tr')[0];
				var id = jQuery('[attrname="id"]', curentTr).val();
				ids.push(id);
			}
			var url = listUrl + 'batchDelete?ids=' + ids.join();
			confirmx('确认要删除所选课程字典分类记录吗？', function() {
				ajaxDelete(ids.join());
			});
		}
	}
	function ajaxDelete(ids){
		var url = listUrl + 'ajaxDelete?rk='+Math.random();
		var data = {ids:ids};
	    jQuery.ajax({  
			url: url, async : false,type: "POST",
			data : data,
			success: function(response) {
				info = response;
				if(info.success == '1'){
					queryList();
					parent.refreshTree();
				}
				alertx(info.message);
			},
			error: function(e){console.error(e);}
		});
	}
	function submitData(){ //提交表单
		var formObj = null;
		if(obj == null){
			formObj = jQuery("#searchForm")[0];
		}else{
			formObj = jQuery(obj).parents('form')[0];
		}
		if(formObj!=null){
			formObj.submit();
		}
	}
	
	function resetForm(obj) { //重置查询条件
		var formObj = null;
		if(obj == null){
			formObj = jQuery("#searchForm")[0];
		}else{
			formObj = jQuery(obj).parents('form')[0];
		}
		if (jQuery(formObj)[0] != null) {
			jQuery(formObj)[0].reset();
		}
	}
	
	function clearForm(obj){ //清空查询条件
		var formObj = null;
		if(obj == null){
			formObj = jQuery("#searchForm")[0];
		}else{
			formObj = jQuery(obj).parents('form')[0];
		}
		if (jQuery(formObj)[0] != null) {
			jQuery(formObj).find(':input').each(function(){ 
	            switch(this.type){  
	                case 'passsword':  
	                case 'select-multiple':  
	                case 'select-one':  
	                case 'text': 
	                case 'hidden': 
	                case 'textarea':  
	                    jQuery(this).val('');   //jQuery('.select2-chosen',formObj).html('');
	                    break;  
	                case 'checkbox':  
	                case 'radio':  
	                    this.checked = false;  
	            }  
	            if(this.type.indexOf('select')>-1){
	            	jQuery(this).select2();   //jQuery(this).select2();
	            }
	        });     
		}
	}
	
	function queryList(){
		var form = jQuery('#searchForm')[0];
		form.submit();
	}
	
	function updateSort() {
	  loading('正在提交，请稍等...');
	  var url = $("#listForm").attr("action");
	  $("#listForm").attr("action",sortUrl );
      $("#listForm").submit();
      $("#listForm").attr("action",url );
	}
	
	function ajaxUpdateSort(){
		var url = ajaxSortUrl;
		
		var table = jQuery("#contentTable");
		var checkboxs = jQuery('input[attrname="sort"]', table);
		if (checkboxs.length == 0) {
			alertx("无更新数据！");
			return;
		}
		var ids = [];
		var sorts = [];
		for (var i = 0; i < checkboxs.length; i++) {
			var curentTr = jQuery(checkboxs[i]).parents('tr')[0];
			var id = jQuery('[attrname="id"]', curentTr).val();
			var sort = jQuery('[name="sorts"]', curentTr).val();
			ids.push(id);
			sorts.push(sort);
		}
		
		var data = {ids : ids.join(","),sorts : sorts.join(",")};
	    jQuery.ajax({  
			url: url, async : false,type: "POST",
			data : data,
			success: function(response) {
				info = response;
				if(info.success == '1'){
					queryList();
				}
				alertx(info.message);
			},
			error: function(e){console.error(e);}
		});
	}
	
	function ajaxUpateStatus(id,status){
		var url = statusUrl;
		var data = {id:id,status:status};
	    jQuery.ajax({  
			url: url, async : false,type: "POST",
			data : data,
			success: function(response) {
				info = response;
				if(info.success == '1'){
					queryList();
				}
				alertx(info.message);
			},
			error: function(e){console.error(e);}
		});
	}
	
	function ajaxUpateShow(isShow){
		var url = ajaxShowUrl;
		
		if(isShow == null || isShow == ''){
			alertx("请选择操作显示或隐藏！");
			return ;
		}
		
		var table = jQuery("#contentTable");
		var checkboxs = jQuery('input[attrname="sort"]:checked', table);
		if (checkboxs.length == 0) {
			alertx("请选择至少一行数据！");
			return;
		}
		var ids = [];
		for (var i = 0; i < checkboxs.length; i++) {
			var curentTr = jQuery(checkboxs[i]).parents('tr')[0];
			var id = jQuery('[attrname="id"]', curentTr).val();
			ids.push(id);
		}
		
		var data = {ids : ids.join(","),isShow : isShow};
	    jQuery.ajax({  
			url: url, async : false,type: "POST",
			data : data,
			success: function(response) {
				info = response;
				if(info.success == '1'){
					queryList();
				}
				alertx(info.message);
			},
			error: function(e){console.error(e);}
		});
	}
	
</script>
<style type="text/css">
.tableHead th, td {
	text-align: center;
}
</style>
</head>
<body>
	
	<form:form id="searchForm" modelAttribute="curriculumDictCategory" action="${ctx}/sys/curriculumDictCategory/list" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		
		<ul class="ul-form">
			<li><label>编码：</label>
				<form:input path="code" htmlEscape="false" maxlength="100" class="input-medium"/>
			</li>
			<li><label>名称：</label>
				<form:input path="name" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			<li><label>上级ID：</label>
				<%-- <sys:treeselect id="parentId" name="parentId" value="${curriculumDictCategory.parentId}" labelName="" labelValue="${parentId.name}"
					title="上级ID" url="/sys/curriculumConfig/getAllTreeDatas" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
				 --%>
				 <form:input path="parentId" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			
			<li class="clearfix"></li> 
		</ul>
		<br>
		<div style="text-align: right;display: block;">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
				<input id="btnReset" class="btn " type="reset" value="重置" onclick="resetForm(this)"/>
				<input id="btnClear" class="btn " type="button" value="清除" onclick="clearForm(this)"/>
		</div>
	</form:form>
	<sys:message content="${message}"/>
	<div class="" style="margin-bottom: 3px;">
			<input id="btnAdd" class="btn btn-primary" type="button" value="新 增" onclick="add()"/>&nbsp;
			<input id="btnEdit" class="btn btn-primary" type="button" value="修 改" onclick="edit()"/>&nbsp;
			<!-- <input id="btnDel" class="btn btn-primary" type="button" value="删 除" onclick="del()"/>&nbsp; -->
			<!-- <input id="btnSort" class="btn " type="button" value="保存排序" onclick="ajaxUpdateSort()"/> -->
			<input id="btnShow" class="btn " type="button" value="显示" onclick="ajaxUpateShow('1')"/>
			<input id="btnHide" class="btn " type="button" value="隐藏" onclick="ajaxUpateShow('0')"/>
			<input id="btnDetail" class="btn " type="button" value="查 看" onclick="detail()"/>&nbsp;
	</div>
	
	<form id="listForm" method="post">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr class="tableHead">
				<th style="text-align:center;" onclick="toggleCheckBox('checkboxName',this)">
		  			<input type="checkbox" checkboxName="sort" name="table_form_checkbox_all" value="">
		  		</th>
		  		<th style="text-align:center;">序号</th>
				<th>编码</th>
				<th>名称</th>
				<th>排序</th>
				<th>备注</th>
				<shiro:hasPermission name="sys:curriculumDictCategory:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="curriculumDictCategory" varStatus="status">
			<tr>
				<td style="text-align:center;" >
					<input type="checkbox" name="sort" attrname="sort" value="">
					<input type="hidden" attrname="id" value="${curriculumDictCategory.id}"/>
					<input type="hidden" attrname="code" value="${curriculumDictCategory.code}"/>
					<input type="hidden" attrname="name" value="${curriculumDictCategory.name}"/>
					<input type="hidden" attrname="parentIds" value="${curriculumDictCategory.parentIds}"/>
					<input type="hidden" attrname="parentId" value="${curriculumDictCategory.parentId}"/>
					<input type="hidden" attrname="remarks" value="${curriculumDictCategory.remarks}"/>
					<input type="hidden" attrname="createTime" value="${curriculumDictCategory.createTime}"/>
					<input type="hidden" attrname="createBy" value="${curriculumDictCategory.createBy}"/>
					<input type="hidden" attrname="updateTime" value="${curriculumDictCategory.updateTime}"/>
					<input type="hidden" attrname="updateBy" value="${curriculumDictCategory.updateBy}"/>
					<input type="hidden" attrname="delFlag" value="${curriculumDictCategory.delFlag}"/>
				</td>
				<td style="text-align:center;">
					<span attrname="number">${ status.index + 1}</span>
				</td>
				<td title=""><a href="javascript:void(0);" onclick="detail(this)">
					${curriculumDictCategory.code}
				</a></td>
				<td title="">
					${curriculumDictCategory.name}
				</td>
				<td style="vertical-align: middle;text-align: center;">
					<input type="hidden" name="ids" value="${permission.id}"/>
					<input type="text" name="sorts" value="${permission.sort}" maxlength="50" class="required" style="width:50px;height: 14px;margin: 0px;"/>
				</td>
				<td title="">
					${curriculumDictCategory.remarks}
				</td>
				<td>
					<a href="javascript:void(0);" onclick="edit(this)">修改</a>
					<!-- <a href="javascript:void(0);" onclick="del(this)">删除</a> -->
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	</form>
	
	
	<div style="height: 50px;width: 100%;"></div>
</body>
</html>